import React from 'react'
import Action from '../../../../action/action'
import Store from '../../../../store/store'
import ReactMixin from 'react-mixin'
import Reflux from 'reflux'
import {Link} from 'react-router'


import EmptyBox from '../../../../component/emptyBox/emptyBox'
import SideNavBar from '../../../../component/sideNavBar/sideNavBar'

export default class ShoppingAddress extends React.Component{
    constructor(props){
        super(props);
        this.state = {
            userInfo : {},
        }
    }
    componentDidMount(){
        Action.getUserInfo()
    }
    render(){
        let userInfo = this.state.userInfo;
        let list = [];
        userInfo.userAddress && userInfo.userAddress.map((item,i)=>{
            list.push(
                <li key={i}>
                    <h4>
                        <span>{item.name}</span>
                        {item.phone[0]+item.phone[1]+item.phone[2]+"****"+item.phone[7]+item.phone[8]+item.phone[9]+item.phone[10]}
                    </h4>
                    <p>{item.address + item.place}</p>
                    <div>
                        <div>
                            <i className={`iconfont ${item.isDef ? "icon-xuanze" : "icon-xuanze1"}`}></i>
                            <span>默认地址</span>
                        </div>
                        <div>
                            <Link to="/my/editAddress">
                                <i className="iconfont icon-bianji"></i>
                                <span>编辑</span>
                            </Link>
                            <a>
                                <i className="iconfont icon-iconfontshanchu"></i>
                                <span>删除</span>
                            </a>
                        </div>
                    </div>
                </li>
            )
        })
        return(
            <div className="ShoppingAddress">
                <ul>
                    {list.length > 0 ? list : <EmptyBox type="noAddress" size="72%"/>}
                </ul>
                <Link to="/my/addAddress" className="footBtn">
                    <div>
                        <i className="iconfont icon-tianjia"></i>
                        <span>添加地址</span>
                    </div>
                </Link>
                <SideNavBar/>
            </div>
        )
    }
}

ReactMixin.onClass(ShoppingAddress,Reflux.connect(Store));